// $Id: Function.java 1905 2011-01-10 14:18:29Z phil $

package sma.jade;

/**
 * Generic function object for test application for
 *   distributed computations.
 * The object embeds the actual function, the interval boundaries
 *   and the stepsize for the integral computation.
 * @author laroque@u-cergy.fr
 * @version $Rev: 1905 $
 */
public class Function implements java.io.Serializable {

  /** lower bound for computation interval */
  public final double min;

  /** upper bound for computation interval */
  public final double max;

  /** granularity for computation interval */
  public final double delta;

  /** default function (redefined in subclasses) */
  public double f(double x) { return 0; }

  /** actual computation of the integral */
  public double eval() {
    double result = 0;
    for (double x = min; x < max; x += delta)
      result += (delta * f(x));
    return result;
  }

  /** The constructor initialzes the compuation parameters.
   * @param min  lower bound for computation interval
   * @param max  upper bound for computation interval
   * @param delta granularity of the computation
   */
  public Function(double min, double max, double delta) {
    this.min = min;
    this.max = max;
    this.delta = delta;
  }
}
